/**
 * 图片 (数据类)
 */
function sImage(target) {
    if(this.initialize) return;

    sElement.call(this, "sImage");

    var thiz = target ? target : this;
    
    this.src = thiz.src;
    
    var style = thiz.style ? thiz.style : {};
    if(!style.display){
        style.display = "inline-block";
    }
    
    var styles = ["width", "height"];

    /**
     * 定义attributes
     */
    Object.defineProperty(this, "style", { 
        get: function(){
            return style;
        },
        set: function(val){
            if(!val || typeof(val) !== "object") return;
            for(let i in val){
                if(styles.indexOf(i) < 0) continue;
                style[i] = val[i];
            }
        },
        enumerable: true
    });

    var attributes = {
        id: thiz.id,
        name: thiz.name,
        width: style.width,
        height: style.height,
        ...thiz.attributes
    };

    /**
     * 定义attribute
     */
    Object.defineProperty(this, "attributes", { 
        get: ()=>{
            attributes.width = this.style.width;
            attributes.height = this.style.height;
            attributes.position = this.style.position;
            return attributes;
        },
        set: (val)=>{
            if(!val || typeof(val) !== "object") return;
            updateAttributes.call(this, val);
        },
        enumerable: true
    });

    /**
     * 更新属性
     * @param attrs
     */
    var updateAttributes = function (attrs) {
        attributes = { ...attributes, ...attrs };

        this.id = attributes.id;
        this.name = attributes.name;

        if(attributes.width !== undefined){
            style.width = attributes.width;
        }

        if(attributes.height !== undefined){
            style.height = attributes.height;
        }
    }

}

/**
 * 将sElement原型上的方法和属性赋值给sImage原型
 */
for(let i in sElement.prototype){
    sImage.prototype[i] = sElement.prototype[i];
}